//
//  ProductInfoTableViewCell.m
//  ChunLaiZhuangClient
//
//  Created by xielihui on 16/4/19.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "ProductInfoTableViewCell.h"
#import "ProdcutDetaiModel.h"

@interface ProductInfoTableViewCell()
@property(nonatomic, strong) ProdcutDetaiModel *productModel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *standardPriceTipLabel;
@property (weak, nonatomic) IBOutlet UILabel *standardPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *chunlaiTextLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *spaceLineHeightCons;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nameLabelConstraint;
@end
@implementation ProductInfoTableViewCell

- (void)awakeFromNib {
    // Initialization code
    self.spaceLineHeightCons.constant = .33f;
}

- (void)updateWithProductModel:(ProdcutDetaiModel *)productModel {
    self.productModel = productModel;
    NSString *special = self.productModel.data.special;
    if (special.length > 0) {
        self.priceLabel.text = self.productModel.data.special;
        NSMutableAttributedString *attri = [self.productModel.data.price getAttributeStringWithMinddleLine];
        [self.standardPriceLabel setAttributedText:attri];
    } else {
        self.standardPriceLabel.hidden = YES;
        self.standardPriceTipLabel.hidden = YES;
        self.priceLabel.text = self.productModel.data.price;
    }
    //self.nameLabel.preferredMaxLayoutWidth = SCREEN_WIDTH;
    self.nameLabel.text = self.productModel.data.name;
  CGSize size=[self.productModel.data.name sizeWithFont:[UIFont systemFontOfSize:16] maxSize:CGSizeMake(SCREEN_WIDTH-14-12, MAXFLOAT)];
    self.nameLabelConstraint.constant=size.height+2;
   // [self.nameLabel sizeToFit];
    
    
//    *返回值是该字符串所占的大小(width, height)
//    *font : 该字符串所用的字体(字体大小不一样,显示出来的面积也不同)
//    *maxSize : 为限制字体的最大宽和高(如果显示一行,则宽高都设置为MAXFLOAT, 如果显示为多行,只需将宽设置一个有限定长值,高设置为MAXFLOAT)
//    */
//    -(CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize;
    [self.priceLabel sizeToFit];
    [self.standardPriceLabel sizeToFit];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
